package com.pure.common.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: zhangjl
 * @Date: 22-1-16
 * @Description:
 */
public final class EnumDictRegistry {
    private static final Map<String, List<?>> ALL_ENUMS = new HashMap<>();

    private EnumDictRegistry() {

    }

    public static <E extends Enum & BaseEnum> void add(Class<E> e) {
        E[] enumItems = e.getEnumConstants();
        ALL_ENUMS.put(StringUtils.lowerCase(enumItems[0].enumName()), Arrays.asList(enumItems));
    }

    @SuppressWarnings("unchecked")
    public static <E extends BaseEnum> List<E> get(String enumName) {
        return (List<E>) ALL_ENUMS.get(StringUtils.lowerCase(enumName));
    }
}
